package videoDuration.V2;

import java.io.File;

import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.EncoderException;
import it.sauronsoftware.jave.InputFormatException;
import it.sauronsoftware.jave.MultimediaInfo;
/**
 * 文件夹下面文件视频时长
 * @author Administrator
 *
 */
public class GetVideoTime {

    void GetTime(String path){
        //Get File paths
        File[] files = new File(path).listFiles();

        //Print the files name in the path
        for(int i = 0; i < files.length; i++){
            String str = files[i].getName();
            System.out.println(str);
        }

        //Create Encoder and MultimediaInfo Object
        Encoder encoder = new Encoder();
        MultimediaInfo multinfo;

        long totalTime = 0L;
        long duration = 0L;

        for(int i = 0; i < files.length; i++){
            try {
                multinfo = encoder.getInfo(files[i]);
                duration = multinfo.getDuration();
                totalTime += duration;
                //System.out.print(multinfo.getDuration());
                //System.out.print("  ");
            } catch (InputFormatException e) {
                e.printStackTrace();
            } catch (EncoderException e) {
                e.printStackTrace();
            }
        }

        System.out.print(totalTime/(3600*1000) + ":" 
        + totalTime%(3600*1000)/(60*1000)+ ":" 
        + totalTime%(3600*1000)%(60*1000)/1000);

    }

    public static void main(String args[]) {
        GetVideoTime gettime = new GetVideoTime();
        //gt.GetTime("E:\\SSH-JavaEE\\workspace\\SSHDemo\\src\\com\\hotelMana\\action\\user");
        gettime.GetTime("D:\\springUpload\\v");
    }
}

